package com.jeasonzhao.commons.parser.expression.library;

import com.jeasonzhao.commons.parser.expression.AbstractEvalProvider;
import com.jeasonzhao.commons.parser.expression.EvalException;
import com.jeasonzhao.commons.parser.expression.EvalProviderHelper;
import com.jeasonzhao.commons.parser.expression.ValuePair;
import com.jeasonzhao.commons.utils.DataTypes;

public class CommonEvalLibrary extends AbstractEvalProvider
{
    private static volatile CommonEvalLibrary m_instance = null;
    public static final CommonEvalLibrary getInstance()
    {
        if(null == m_instance)
        {
            synchronized(CommonEvalLibrary.class)
            {
                m_instance = new CommonEvalLibrary();
            }
        }
        return m_instance;
    }

    private CommonEvalLibrary()
    {
        super();
        try
        {
            EvalProviderHelper.addFunctionByClass(this,DateOperations.class);
            EvalProviderHelper.addFunctionByClass(this,MathOperations.class);
            EvalProviderHelper.addFunctionByClass(this,CommonOperations.class);
            this.addVariable("null",new ValuePair(null));
            this.addVariable("true",new ValuePair(Boolean.TRUE,DataTypes.BOOL));
            this.addVariable("false",new ValuePair(Boolean.FALSE,DataTypes.BOOL));
        }
        catch(EvalException ex)
        {
        	ex.printStackTrace();
        }
    }
}
